package com.mybatis.test;

import com.mybatis.dao.OrderDao;
import com.mybatis.dao.UserDao;
import com.mybatis.domain.Order;
import com.mybatis.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisTest3 {

    private UserDao mapper;

    @Before
    public void before() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sqlSessionFactory.openSession(true);
        mapper = sqlSession.getMapper(UserDao.class);
    }

    @Test
    public void testSave() {
        List<User> all = mapper.findUserByRoleAll();

        all.forEach(k -> {
            System.out.println(k);
        });
    }

}
